package cn.fntop.weixin;

import cn.fntop.weixin.config.WxConfigLoader;
import com.jfinal.weixin.sdk.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.env.Environment;

import java.util.List;

@SpringBootApplication
@Slf4j
public class FnWeixinDemoApplication implements EnvironmentAware {
    @Autowired
    private List<WxConfigLoader> wxConfigLoader;

    public static void main(String[] args) {
        SpringApplication.run(FnWeixinDemoApplication.class, args);
    }

    @Override
    public void setEnvironment(Environment environment) {
        //this is local to WeixinAppConfig.java
        wxConfigLoader.sort(AnnotationAwareOrderComparator.INSTANCE);
        WxConfigLoader configLoader = wxConfigLoader.get(wxConfigLoader.size() - 1);
        log.info("\n##########公众号配置##########\n{}\n##########小程序配置##########\n{}",
                JsonUtils.toJson(configLoader.loadWx()),
                JsonUtils.toJson(configLoader.loadWxa()));
    }
}
